package com.itheima.controller;

import com.itheima.pojo.Clazz;
import com.itheima.pojo.ClazzQueryParam;
import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.servise.ClazzServise;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clazzs")
public class ClazzController {
    @Autowired
    private ClazzServise clazzServise;
    // 查询所有
    @GetMapping("/list")
    public Result getAll(){
        List<Clazz> all = clazzServise.getAll();
        return Result.success(all);
    }
    // 添加班级
    @PostMapping
    public Result addClass(@RequestBody Clazz clazz){
        clazzServise.addClass(clazz);
        return Result.success();
    }
    // 根据id删除班级
    @DeleteMapping("/{id}")
    public Result deleteClass(@PathVariable Integer id){
        clazzServise.deleteClass(id);
        return Result.success();
    }
    //根据id查询
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Clazz clazz = clazzServise.getById(id);
        return Result.success(clazz);
    }
    //修改
    @PutMapping
    public Result updateClass(@RequestBody Clazz clazz){
        clazzServise.putClass(clazz);
        return Result.success();
    }
    //班级列表查询
    @GetMapping
    public Result list(ClazzQueryParam param){
        PageBean page = clazzServise.page(param);
        return Result.success(page);
    }


}
